  var XMLHttpReq,pid;                                                             //创建XMLHttpRequest对象
  function createXMLHttpRequest()
  {
  	if(window.XMLHttpRequest)
  	{                               
  		//Mozilla浏览器
        XMLHttpReq = new XMLHttpRequest();
    }else if(window.ActiveXObject)
    {                           
    	//IE浏览器
        try
        {
            XMLHttpReq = new ActiveXObject( "Msxm12.XMLHTTP" );
        }catch(e)
        {
            try
            {
               XMLHttpReq = new ActiveXObject( "Microsoft.XMLHTTP" );
            }catch(e)
            {}
         }
      }
  }  
  //发送Ajax请求
  function sendAjaxRequest(url)
  {
     createXMLHttpRequest();                         //创建XMLHttpRequest对象
     XMLHttpReq.open("post",url,false);
     XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
     XMLHttpReq.send(null);
  }

  //回调函数processResponse
  function processResponse()
  {
      if(XMLHttpReq.readyState == 4)
      {
      	 if(XMLHttpReq.status == 200)
      	 {
            var subTypes = XMLHttpReq.responseXML.getElementsByTagName("subType");
            var type = document.getElementById("type");
            var subType = document.getElementById("subType");
            if(pid == 0)
            {
            	subType.options.length = 0;
                addOption(type,subTypes);
                subType.add(new Option("请选择",""));
            }else
            {
            	subType.options.length = 0;
                addOption(subType,subTypes);
            }
         }else
         {    
         	  //响应未交互成功时，页面中的代码
              // "正在加载数据......"
         }
     }else
     {                                                  
     	//响应未加载成功时，页面中的代码
        // "正在验证用户名......"
     }
  }
  
  function addOption(selectObject,subType)
  {
 	 for( var i = 0; i < subType.length; i=i+1 ) 
 	 {
	     var subTypeIndex = subType[i];
	     var subTypeId = subTypeIndex.getElementsByTagName( "subTypeId" ).item(0).firstChild.nodeValue;
	     var subTypeName = subTypeIndex.getElementsByTagName( "subTypeName" ).item(0).firstChild.nodeValue;
	     if(i == 0)
	     {
	    	 selectObject.add(new Option("请选择", 0));
		     selectObject.add(new Option(subTypeName,subTypeId));
	     }else
	     {
	    	 selectObject.add(new Option(subTypeName,subTypeId));
	     }	      
	 }
  }
  
  function getSubTypes(typeId)
  {
	  pid = typeId.value ;
	  var url = "getType!getSubTypeByTypeId.action?type="+typeId;
	  sendAjaxRequest(url);
	  
  } 
  function setUp()
  {
	  getSubTypes(0);
  }  
  onload = setUp;
  
  
  
  
  
  
  
  
  
  
  
  
  
 